#-------------------------------------------------------------------------------
# Name:        make_package.py
# Purpose:     ?????????
#
# Author:      Lotte
#
# Created:     12/08/2012
# Copyright:   (c) Lotte 2012
# Licence:     <your licence>
#-------------------------------------------------------------------------------

import os,sys

py_file = "from distutils.core import setup \r\n import py2exe \r\n setup(console=['%s']) \r\n "

def init(py_name,out_path):
    if os.path.exists(out_path) == True :
        print "path is exist"
        return False
    os.makedirs(out_path)
    setupfile = out_path + "/setup.py"
    setup = open(setupfile,"w")
    setup.write( "from distutils.core import setup \r\nimport py2exe \r\nsetup(console=[r'%s']) \r\n " % py_name)
    setup.close()
    return True


def make():
    pass



def main():
    if len(sys.argv) < 2:
        print "cmd format: make_package.py py_file\r\n"
        exit(0)

    py_file = os.path.abspath(sys.argv[1])
    out_path = "./exe/%s" % os.path.splitext(os.path.basename(sys.argv[1]))[0]
    out_path = os.path.abspath(out_path)

    print "py file:" + py_file
    print "out put dir:" + out_path

    if init(py_file,out_path) == False:
        print "error"
        exit(0)

    os.chdir(out_path)

    os.system("%s/setup.py py2exe" % out_path)

if __name__ == '__main__':
    main()

